package com.ruoyi.activiti.service.impl;

import java.util.List;

import com.ruoyi.activiti.service.IProcessService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.activiti.mapper.BizExamMapper;
import com.ruoyi.activiti.domain.BizExam;
import com.ruoyi.activiti.service.IBizExamService;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;

/**
 * 试卷审核Service业务层处理
 * 
 * @author marui
 * @date 2023-10-28
 */
@Service
public class BizExamServiceImpl implements IBizExamService 
{
    @Resource
    private BizExamMapper bizExamMapper;
    @Autowired
    private IProcessService processService;

    /**
     * 查询试卷审核
     * 
     * @param id 试卷审核ID
     * @return 试卷审核
     */
    @Override
    public BizExam selectBizExamById(Long id)
    {
        return bizExamMapper.selectBizExamById(id);
    }

    /**
     * 查询试卷审核列表
     * 
     * @param bizExam 试卷审核
     * @return 试卷审核
     */
    @Override
    @DataScope(deptAlias = "sys_dept",userAlias="sys_user")
    public List<BizExam> selectBizExamList(BizExam bizExam)
    {
        if (!SecurityUtils.isAdmin(SecurityUtils.getLoginUser().getUser().getUserId())) {
            bizExam.setCreateBy(SecurityUtils.getUsername());
        }
        List<BizExam> list = bizExamMapper.selectBizExamList(bizExam);
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(item -> {
                try {
                    processService.richProcessField(item);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
        return list;
    }

    /**
     * 新增试卷审核
     * 
     * @param bizExam 试卷审核
     * @return 结果
     */
    @Override
    public int insertBizExam(BizExam bizExam)
    {
        bizExam.setCreateBy(SecurityUtils.getUsername());
        bizExam.setCreateTime(DateUtils.getNowDate());
        return bizExamMapper.insertBizExam(bizExam);
    }

    /**
     * 修改试卷审核
     * 
     * @param bizExam 试卷审核
     * @return 结果
     */
    @Override
    public int updateBizExam(BizExam bizExam)
    {
        bizExam.setUpdateTime(DateUtils.getNowDate());
        return bizExamMapper.updateBizExam(bizExam);
    }

    /**
     * 批量删除试卷审核
     * 
     * @param ids 需要删除的试卷审核ID
     * @return 结果
     */
    @Override
    public int deleteBizExamByIds(Long[] ids)
    {
        return bizExamMapper.deleteBizExamByIds(ids);
    }

    /**
     * 删除试卷审核信息
     * 
     * @param id 试卷审核ID
     * @return 结果
     */
    @Override
    public int deleteBizExamById(Long id)
    {
        return bizExamMapper.deleteBizExamById(id);
    }
}
